package cn.u313.repository;

import cn.u313.entry.BlessingEntry;
import cn.u313.entry.DragonBoatFestivalEntry;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

public interface DragonBoatFestivalRepository extends JpaRepository<DragonBoatFestivalEntry, String>, JpaSpecificationExecutor<DragonBoatFestivalEntry> {

        @Query(nativeQuery = true,value = "SELECT count(1) FROM t_dragon_boat_festival_2022 " +
                "where date_sub(curdate(),interval 0 day)<=add_date " +
                "and qq=:qq " +
                "and ref_zong =:type ")
        int countByDateDow(String qq,String type);
        @Query(nativeQuery = true,value = "\n" +
                "SELECT * FROM t_dragon_boat_festival_2022 " +
                "where date_sub(curdate(),interval 0 day)<add_date and qq=:qq and has_invalid = 0")
        List<DragonBoatFestivalEntry> byQQAndToDay(String qq);
        @Query(nativeQuery = true,value = "\n" +
                "SELECT * FROM t_dragon_boat_festival_2022 " +
                "where date_sub(curdate(),interval 0 day)<add_date and qq=:qq and has_invalid = 0 and id =:code ")
        DragonBoatFestivalEntry getById(String qq, String code);

        @Modifying
        @Query(nativeQuery = true,value =  "\n" +
                "update  t_dragon_boat_festival_2022 set has_invalid = 1 " +
                "where date_sub(curdate(),interval 0 day)<add_date and qq=:qq and has_invalid = 0")
        int updateU(String qq);

}